/*
* $Id: TypeStore.java 292 2011-03-24 21:08:17Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary.db;

import java.io.*;

/**
 * Types database
 * @author lexus
 */
public class TypeStore extends DBStore
{
//--------------------------------Types of hive---------------------------------
    public static final int TYPEH_8 = 0;
    public static final int TYPEH_10 = 1;
    public static final int TYPEH_12 = 2;
    public static final int TYPEH_16 = 3;
    public static final int TYPEH_18 = 4;
    public static final int TYPEH_20 = 5;
    public static final int TYPEH_24 = 6;
    public static final int TYPEH_NONSDT = 7;
//-------------------------------Types of frame---------------------------------
    public static final int TYPEF_300 = 0;
    public static final int TYPEF_230 = 1;
    public static final int TYPEF_180 = 2;
    public static final int TYPEF_SECTION = 3;
    public static final int TYPEF_W230 = 4;
    public static final int TYPEF_W180 = 5;
    public static final int TYPEF_NONSDT = 6;
//--------------------------------Database names--------------------------------
    public static final String TYPE_HOUSING_STORE = "db_type_housing";
    public static final String TYPE_FRAME_STORE = "db_type_frame";

    /**
     * Container of type records
     * @author lexus
     */
    public class TypeRecord extends DBRecord
    {
        /** Identificator of type */
        public int idType;
        /** name of type. Name is empty if identificator < 6 or 7 */
        public String nameType;

        /**
         * Constructor
         */
        public TypeRecord() {
            nameType = new String();
        }

        /**
         * Gets byte array of record
         * @return byte array
         */
        public byte[] getData() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(baos);
                dos.writeInt(idType);
                dos.writeUTF(nameType);
                return baos.toByteArray();
            } catch (IOException ex) {}
            return null;
        }

        /**
         * Sets byte array record.
         * Array will be parsed and all fields of it will be filled
         * @param dis data input stream
         */
        public void setData(DataInputStream dis) throws IOException{
                idType = dis.readInt();
                nameType = dis.readUTF();
        }
    }

    /**
     * Constructor
     */
    public TypeStore(String nameStore) {
        super("nameStore");
    }
    
    /**
     * Gets new record
     * @return new record
     */
    public DBRecord getRecord() {
        return new TypeRecord();
    }
}
